# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=aubio
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.9
pkgrel=2
pkgdesc='A tool for extracting annotations from audio signals (mingw-w64)'
url='https://aubio.org/'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-libsamplerate"
         "${MINGW_PACKAGE_PREFIX}-libsndfile"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-waf"
             "python")
source=(https://aubio.org/pub/aubio-${pkgver}.tar.bz2
        0001-fix-AUBIO_STRERROR-definition.patch
        0002-wscript-disable-tests.patch
        0003-waf-disable-def-install.patch
        0004-wscript-fix-implib-name.patch)
sha256sums=('d48282ae4dab83b3dc94c16cf011bcb63835c1c02b515490e1883049c3d1f3da'
            'c504cc0f6a80588cec94941fa9a1bb6338aea616f70a1ee1074ef19cb16c82da'
            '3c9da6fcaab3a96afeff50db8979920d8fcb7749cdb5d34400e2a6275fff614a'
            '09df1bdba2e3b34251a746380e65967bdf38a70182315b077b27aacdeab7672e'
            'f53a1b4ae636d4ec03a038535479bd83f8a37ceb3d3b0f8f37697efb7b0b1329')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # https://github.com/aubio/aubio/pull/349
  patch -p1 -i "${srcdir}/0001-fix-AUBIO_STRERROR-definition.patch"

  patch -p1 -i "${srcdir}/0002-wscript-disable-tests.patch"
  patch -p1 -i "${srcdir}/0003-waf-disable-def-install.patch"
  patch -p1 -i "${srcdir}/0004-wscript-fix-implib-name.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  LDFLAGS+=" -pthread" \
  DEST_OS=win32 \
  TARGET=${MINGW_CHOST} \
  PKG_CONFIG=${MINGW_PREFIX}/bin/pkgconf \
  AR=${MINGW_PREFIX}/bin/ar \
  WINDRES=${MINGW_PREFIX}/bin/windres \
  /usr/bin/python ./waf configure \
    --prefix=${MINGW_PREFIX} \
    --check-c-compiler=${CC} \
    --with-target-platform=win32 \
    --enable-fftw3 \
    --disable-docs \
    --disable-tests \
    --notests \
    --out="${srcdir}/build-${MSYSTEM}"

  /usr/bin/python ./waf build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  /usr/bin/python ./waf install --destdir="${pkgdir}"
  mv "${pkgdir}${MINGW_PREFIX}"/lib/*.dll "${pkgdir}${MINGW_PREFIX}/bin/"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
